package com.pine.manager.pineframework;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.pine.dao.pineframework.entity.SysApprovalHistory;
import com.pine.dao.pineframework.mapper.SysApprovalHistoryMapper;
import com.pine.manager.core.BaseManager;
import com.pine.manager.pineframework.bo.SysApprovalHistoryBo;
import com.pine.manager.pineframework.convertors.SysApprovalHistoryConvertor;
import com.pine.manager.pineframework.query.SysApprovalHistoryQuery;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 系统审批历史表 管理类
 * </p>
 *
 * @author pine manage
 * @since 2024-10-31
 */
@Component
public class SysApprovalHistoryManager extends BaseManager<SysApprovalHistoryMapper, SysApprovalHistory, Long, SysApprovalHistoryBo, SysApprovalHistoryQuery, SysApprovalHistoryConvertor> {

    @Resource
    private SysApprovalHistoryConvertor sysApprovalHistoryConvertor;

    @Override
    public LambdaQueryWrapper<SysApprovalHistory> encapsulateQueryWrapper(SysApprovalHistoryQuery query) {
        LambdaQueryWrapper<SysApprovalHistory> queryWrapper = super.encapsulateQueryWrapper(query);
        if (query == null) {
            return queryWrapper;
        }

        // 组装查询条件
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getApprovalId()), SysApprovalHistory::getApprovalId, query.getApprovalId());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getName()), SysApprovalHistory::getName, query.getName());
        queryWrapper.in(ObjectUtils.isNotEmpty(query.getStatus()), SysApprovalHistory::getStatus, query.getStatus());
         queryWrapper.eq(ObjectUtils.isNotEmpty(query.getCreateUserId()), SysApprovalHistory::getCreateUserId, query.getCreateUserId());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getCreateUsername()), SysApprovalHistory::getCreateUsername, query.getCreateUsername());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getActionUserId()), SysApprovalHistory::getActionUserId, query.getActionUserId());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getActionUsername()), SysApprovalHistory::getActionUsername, query.getActionUsername());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getActionTimeStart()), SysApprovalHistory::getActionTime, query.getActionTimeStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getActionTimeEnd()), SysApprovalHistory::getActionTime, query.getActionTimeEnd());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getRemark()), SysApprovalHistory::getRemark, query.getRemark());

        return queryWrapper;
    }
}
